package com.abc.robot01.flutter

import android.os.Bundle
import android.util.Log
import androidx.annotation.NonNull
import com.abc.robot01.activity.H5Activity
import com.abc.robot01.activity.startActivity
import com.abc.robot01.vivemodel.Robot
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugins.GeneratedPluginRegistrant


class CustomerRenderDetails : FlutterActivity() {
    val CHANNEL: String = "com.abc.robot01.flutter.CustomerRenderDetails"

    var customerName = ""
    var customerPhone = ""
    var totalAmount = ""


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        customerName = intent.getStringExtra("customerName")!!
        customerPhone = intent.getStringExtra("customerPhone")!!
        totalAmount = intent.getStringExtra("totalAmount")!!
    }

    override fun getInitialRoute(): String {
        // 指定加载的 Flutter 界面
        return "/customerRenderDetails"
    }

    override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
        GeneratedPluginRegistrant.registerWith(flutterEngine)
        MethodChannel(flutterEngine.getDartExecutor().getBinaryMessenger(), CHANNEL)
            .setMethodCallHandler { call, result ->
                if (call.method!!.contentEquals("getId")) {
                    val  a =  Robot.accessToken + "_" + Robot.userId + "_" +
                            Robot.companyId + "_" + customerName + "_" + customerPhone + "_" + totalAmount
                    Log.e("CustomerRenderDetails",""+a);
                    result.success(a)
                    return@setMethodCallHandler
                }
                if (call.method!!.contentEquals("launchActivity")) {
                 val id =   call.argument<String>("id");
                 val url =   call.argument<String>("url");
                    startActivity<H5Activity>() {
                        putExtra("id", id)
                        putExtra("url", url)
                    }
                    result.success("ok")
                    return@setMethodCallHandler
                }
            }
    }
}



